package com.hao;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class HelloWord {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 1.创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        // 2.设置参数
        factory.setHost("8.130.120.148");
        factory.setPort(5672);
        factory.setVirtualHost("/kaiyuan");
        factory.setUsername("shihao");
        factory.setPassword("shihao");
        // 3.创建连接Connection
        Connection connection = factory.newConnection();
        // 4.创建Channel
        Channel channel = connection.createChannel();
        // 5.创建Queue
        channel.queueDeclare("hello_world",true,false,true,null);
        // 6.发送消息
        String body = "hello rabbitmq11~~~";
        channel.basicPublish("","hello_world",null,body.getBytes());
        // 7.关闭连接
        channel.close();
        connection.close();
    }
}
